package api

import (
	"net/http"

	"github.com/julienschmidt/httprouter"
)

/**
 * Healthcheckhandler:用于处理健康检查请求
 */
func (api *Api) healthCheckHandler(w http.ResponseWriter, r *http.Request) {
	data := map[string]interface{} {
		"status": "available",
		"system_info": map[string]string {
			"environment": api.config.Env,
			"version": api.Version(),
		},
	}

	resp := api.h.NewResponse(0, data)

	err  := api.h.WriteJSON(w, http.StatusOK, resp, nil)
	if err != nil {
		api.h.ServerErrorResponse(w, r, err)
		w.WriteHeader(http.StatusInternalServerError)
	}
}

/**
 * UtilsRoutes:用于服务健康检查
 */
func (api *Api) utilsRoutes(router *httprouter.Router) {
	router.HandlerFunc(http.MethodGet, "/v1/check", api.healthCheckHandler)
}